package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.FightingLog;
import com.ruoyi.system.service.IFightingLogService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * fightingLogController
 * 
 * @author ruoyi
 * @date 2025-05-23
 */
@Controller
@RequestMapping("/system/log")
public class FightingLogController extends BaseController
{
    private String prefix = "system/log";

    @Autowired
    private IFightingLogService fightingLogService;

    @RequiresPermissions("system:log:view")
    @GetMapping()
    public String log()
    {
        return prefix + "/log";
    }

    /**
     * 查询fightingLog列表
     */
    @RequiresPermissions("system:log:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FightingLog fightingLog)
    {
        startPage();
        List<FightingLog> list = fightingLogService.selectFightingLogList(fightingLog);
        return getDataTable(list);
    }

    /**
     * 导出fightingLog列表
     */
    @RequiresPermissions("system:log:export")
    @Log(title = "fightingLog", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FightingLog fightingLog)
    {
        List<FightingLog> list = fightingLogService.selectFightingLogList(fightingLog);
        ExcelUtil<FightingLog> util = new ExcelUtil<FightingLog>(FightingLog.class);
        return util.exportExcel(list, "fightingLog数据");
    }

    /**
     * 新增fightingLog
     */
    @RequiresPermissions("system:log:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存fightingLog
     */
    @RequiresPermissions("system:log:add")
    @Log(title = "fightingLog", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FightingLog fightingLog)
    {
        return toAjax(fightingLogService.insertFightingLog(fightingLog));
    }

    /**
     * 修改fightingLog
     */
    @RequiresPermissions("system:log:edit")
    @GetMapping("/edit/{userName}")
    public String edit(@PathVariable("userName") String userName, ModelMap mmap)
    {
        FightingLog fightingLog = fightingLogService.selectFightingLogByUserName(userName);
        mmap.put("fightingLog", fightingLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存fightingLog
     */
    @RequiresPermissions("system:log:edit")
    @Log(title = "fightingLog", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FightingLog fightingLog)
    {
        return toAjax(fightingLogService.updateFightingLog(fightingLog));
    }

    /**
     * 删除fightingLog
     */
    @RequiresPermissions("system:log:remove")
    @Log(title = "fightingLog", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fightingLogService.deleteFightingLogByUserNames(ids));
    }
}
